package com.atguigu.gmall.all.controller;

import com.atguigu.gmall.model.product.SkuInfo;
import com.atguigu.gmall.product.client.ProductFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
public class CartController {

    @Autowired
    private ProductFeignClient productFeignClient;

    /**
     * 添加购物车
     * @param request
     * @return
     */
    @GetMapping("addCart.html")
    public String cart(HttpServletRequest request){
        //  需要在后台存储一个skuInfo skuNum;
        //  商品详情页面加入购物车 ：异步操作。
        String skuId = request.getParameter("skuId");
        String skuNum = request.getParameter("skuNum");

        SkuInfo skuInfo = this.productFeignClient.getSkuInfo(Long.parseLong(skuId));

        request.setAttribute("skuInfo",skuInfo);
        request.setAttribute("skuNum",skuNum);

        //  页面名称
        return "cart/addCart";
    }


    /**
     * 查看购物车
     * @return
     */
    @GetMapping("cart.html")
    public String cartList(){
        //  购物车列表页面.
        return "cart/index";
    }


}
